//
//  WZNavigationController.m
//  ETong
//
//  Created by wanzhao on 15/10/28.
//  Copyright (c) 2015年 wanzhao. All rights reserved.
//

#import "WZNavigationController.h"
#import "WZRootViewController.h"
#import "WZOfficeController.h"
#import "WZPersonalController.h"
#import "UIBarButtonItem+category.h"
#import "MJPhotoBrowser.h"

@implementation WZNavigationController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
        
    }
    return self;
}

+ (void)initialize
{
    [super initialize];
    [self setupNavigationBarItem];
    [self setupBarButtonItem];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    if (IsIOS7) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
    self.navigationBar.translucent = NO;
}

- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    
}

+ (void)setupNavigationBarItem
{
    UINavigationBar *nav = [UINavigationBar appearance];
    if (IsIOS7) {
        [nav setBarTintColor:[UIColor whiteColor]];
    } else {
       [nav setBarTintColor:[UIColor whiteColor]];
    }
    
    [nav setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18.0],
                                  NSForegroundColorAttributeName:WhiteColor
                                  }];
    
}

+ (void)setupBarButtonItem
{
    UIBarButtonItem *item = [UIBarButtonItem appearance];
    [item setTitleTextAttributes:@{NSFontAttributeName:Font12,
                                   NSForegroundColorAttributeName:WhiteColor
                                   } forState:UIControlStateNormal];
}



- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    viewController.navigationItem.hidesBackButton = YES;
    if (self.viewControllers.count > 1) {
        
        viewController.hidesBottomBarWhenPushed = YES;
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem BarButtonItemWithImageName:@"call_back" title:@"返回" target:self sel:@selector(popViewControllerAnimated:) titleFont:Font18 titleColor:WhiteColor];
        }
    [super pushViewController:viewController animated:animated];
}


- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated
{
    NSArray *array = [super popToRootViewControllerAnimated:animated];
//    UITabBarController *tab = (UITabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;
//    
//    for (UIView *view in tab.tabBar.subviews) {
//        if ([view isKindOfClass:[UIControl class]]) {
//            [view removeFromSuperview];
//        }
//    }
    
    return array;
}
////必须重写此方法，来删除重新出现的系统的tabbar
- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    NSArray *array = [super popToViewController:viewController animated:animated];
    //    for (UIView *view in viewController.tabBarController.tabBar.subviews) {
//        if ([view isKindOfClass:[UIControl class]]) {
//            [view removeFromSuperview];
//        }
//    }
    
    return array;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(BOOL)shouldAutorotate
{
    return NO;
}
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

@end
